package com.aaa.controller;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.service.TuserService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("tuser")
public class TbUserController {

    @Resource
    private TuserService tuserService;

    // 添加
    // 只要发出的是ajax请求  返回的数据一定要统一格式

    @PostMapping("addUser")
    @ResponseBody
    public LayData insertUser(User user){
        System.out.println("接手过来的参数是:"+user);
        boolean status=tuserService.addUser(user);
        return new LayData(status);
    }
    @GetMapping("query")
    @ResponseBody
    public LayData queryUser(MyPage myPage,User user){
        PageInfo pageInfo=tuserService.queryAll(myPage,user);
        return new LayData(pageInfo);
    }

    @PostMapping("updUser")
    @ResponseBody
    public LayData queryUser(User user){

        boolean status=tuserService.updUser(user);
        return new LayData(status);
    }

    @PostMapping("{username}")
    @ResponseBody
    public LayData queryUserByName(@PathVariable String username){

        boolean user=tuserService.queryByName(username);
        return new LayData(user);
    }


}
